﻿using Songhay.DataAccess.Models;
using Songhay.DataAccess.Models.Extensions;
using Songhay.Mvvm.Models;
using System;
using System.ComponentModel.DataAnnotations;

namespace Songhay.Mvvm.ViewModels
{
    using Extensions;

    /// <summary>
    /// GenericWeb Fragment for MVVM
    /// </summary>
    [MetadataType(typeof(FragmentMetadata))]
    public partial class FragmentViewModel : BindableBaseWithValidation, IFragment
    {
        public FragmentViewModel()
        {
            var dataType = typeof(FragmentViewModel);
            this.SupportMetadataTypeAttribute(dataType);
        }

        public FragmentViewModel(Fragment data)
            : this()
        {
            if (data == null) throw new ArgumentNullException("The expected data is not here.");
            this._data = data;

            this.UpdateViewModel<Fragment, IFragment>(this._data);

            this.PropertyChanged += (s, args) =>
            {
                this.UpdateModel<IFragment, Fragment>(this._data, args.PropertyName);
                var payload = new ModelEventPayload<Fragment> { Model = this._data, IsUpdate = true };
                CorePrismEvents.ModelEventForFragment.Publish(payload);
            };
        }

        public string ClientId
        {
            get { return this._clientId; }
            set
            {
                this.ValidateProperty(this, value);
                this.SetProperty(ref this._clientId, value);
            }
        }

        public DateTime? CreateDate
        {
            get { return this._createDate; }
            set
            {
                this.ValidateProperty(this, value);
                this.SetProperty(ref this._createDate, value);
            }
        }

        public int? DocumentId
        {
            get { return this._documentId; }
            set
            {
                this.ValidateProperty(this, value);
                this.SetProperty(ref this._documentId, value);
            }
        }

        public DateTime? EndDate
        {
            get { return this._endDate; }
            set
            {
                this.ValidateProperty(this, value);
                this.SetProperty(ref this._endDate, value);
            }
        }

        public string FragmentDisplayName
        {
            get { return this._fragmentDisplayName; }
            set
            {
                this.ValidateProperty(this, value);
                this.SetProperty(ref this._fragmentDisplayName, value);
            }
        }

        public int FragmentId
        {
            get { return this._fragmentId; }
            set
            {
                this.ValidateProperty(this, value);
                this.SetProperty(ref this._fragmentId, value);
            }
        }

        public string FragmentName
        {
            get { return this._fragmentName; }
            set
            {
                this.ValidateProperty(this, value);
                this.SetProperty(ref this._fragmentName, value);
            }
        }

        public bool? IsActive
        {
            get { return this._isActive; }
            set
            {
                this.ValidateProperty(this, value);
                this.SetProperty(ref this._isActive, value);
            }
        }

        public bool? IsNext
        {
            get { return this._isNext; }
            set
            {
                this.ValidateProperty(this, value);
                this.SetProperty(ref this._isNext, value);
            }
        }

        public bool? IsPrevious
        {
            get { return this._isPrevious; }
            set
            {
                this.ValidateProperty(this, value);
                this.SetProperty(ref this._isPrevious, value);
            }
        }

        public bool? IsWrapper
        {
            get { return this._isWrapper; }
            set
            {
                this.ValidateProperty(this, value);
                this.SetProperty(ref this._isWrapper, value);
            }
        }

        public string ItemChar
        {
            get { return this._itemChar; }
            set
            {
                this.ValidateProperty(this, value);
                this.SetProperty(ref this._itemChar, value);
            }
        }

        public string ItemText
        {
            get { return this._itemText; }
            set { this.SetProperty(ref this._itemText, value); }
        }

        public DateTime? ModificationDate
        {
            get { return this._modificationDate; }
            set
            {
                this.SetProperty(ref this._modificationDate, value);
            }
        }

        public int? NextFragmentId
        {
            get { return this._nextFragmentId; }
            set
            {
                this.SetProperty(ref this._nextFragmentId, value);
            }
        }

        public int? PrevFragmentId
        {
            get { return this._prevFragmentId; }
            set
            {
                this.ValidateProperty(this, value);
                this.SetProperty(ref this._prevFragmentId, value);
            }
        }

        public byte? SortOrdinal
        {
            get
            {
                return this._sortOrdinal;
            }
            set
            {
                this.ValidateProperty(this, value);
                this.SetProperty(ref this._sortOrdinal, value);
            }
        }

        public override string ToString()
        {
            return this.ToDisplayText();
        }

        string _clientId;
        DateTime? _createDate;
        int? _documentId;
        DateTime? _endDate;
        string _fragmentDisplayName;
        int _fragmentId;
        string _fragmentName;
        bool? _isActive;
        bool? _isNext;
        bool? _isPrevious;
        bool? _isWrapper;
        string _itemChar;
        string _itemText;
        DateTime? _modificationDate;
        int? _nextFragmentId;
        int? _prevFragmentId;
        byte? _sortOrdinal;

        Fragment _data;
    }
}
